/**
 * @Author: Sagan
 * @Date: 2020/09/16 21:47
 */
package module

import (
	"gitee.com/big_meteor/godash/lang"
	"gitee.com/big_meteor/godash/validate/constant"
	"reflect"
)

// 是否为布尔值
// 支持的类型：bool
func Bool(v interface{}) bool {
	return reflect.Bool == lang.GetType(v)
}

func BoolTrue(v interface{}) (bool, error) {
	var rt reflect.Kind
	v, rt = lang.GetValue(v)

	if reflect.Bool != rt {
		return false, constant.ERROR_BOOL_TRUE_UDT
	}

	return true == v.(bool), nil
}

func BoolFalse(v interface{}) (bool, error) {
	var rt reflect.Kind
	v, rt = lang.GetValue(v)

	if reflect.Bool != rt {
		return false, constant.ERROR_BOOL_FALSE_UDT
	}

	return false == v.(bool), nil
}
